﻿#ifndef		__GLOBLE_H__
#define		__GLOBLE_H__
#include <stdlib.h>
#include <stdio.h>
#include <deque>
#include <vector>
#include <list>
#include "jmutex.h"
#include <mmsystem.h>
#include <time.h>

#define G711                    8

#define SENDMODE				1
#define RECVMODE				2


typedef struct UDPHeader
{
	unsigned short src_port;			//远端口
	unsigned short dest_port;			//目的端口
	unsigned short uhl;					//udp头长度
	unsigned short check_num;			//校验和
}udpHeader;

typedef struct
{
	int PayLoadLen;                            //负载长度
	int PayLoadType;                           //负载种类
	bool IsFrame;							   //Marker-M
	unsigned short sNum;                       //顺序号
	unsigned int Timestamp;					   //时间戳
	unsigned char RawData[1024];      //负载
	short DecData[1024*2];			   //G711解码后的
}RTP_INFO;

#pragma pack(1)
typedef struct  
{
	//unsigned char v;
	unsigned char type;
	unsigned short num;
	unsigned int timestamp;
	unsigned int ssrc;
}RTPHead;
#pragma pack()


typedef std::list<RTP_INFO> RTPQUE;

typedef struct MediaInfo
{
	MediaInfo()
	{
		rtpmutex_put.Init();
		//rtpmutex_get.Init();
		//putmutex.Init();
		//getmutex.Init();
	}
	~MediaInfo()
	{
		rtpque_put.clear();
		rtpque_get.clear();
		putque.clear();
		getque.clear();
	}
	RTPQUE rtpque_put;
	JMutex rtpmutex_put;
	RTPQUE rtpque_get;
	//JMutex rtpmutex_get;
	RTPQUE putque;
	//JMutex putmutex;
	RTPQUE getque;
	//JMutex getmutex;
}MediaInfo;

typedef struct frameHeader
{
unsigned int sync1:8;                      //同步信息1
 
unsigned int error_protection:1;       //CRC校验
unsigned int layer:2;                        //层
unsigned int version:2;                    //版本
unsigned int sync2:3;                      //同步信息2
 
unsigned int extension:1;                 //版权
unsigned int padding:1;                   //填充空白字
unsigned int sample_rate_index:2;    //采样率索引
unsigned int bit_rate_index:4;           //位率索引
 
unsigned int emphasis:2;                 //强调方式
unsigned int original:1;                    //原始媒体
unsigned int copyright:1;                 //版权标志
unsigned int mode_extension:2;        //扩展模式，仅用于联合立体声
unsigned int channel_mode:2;          //声道模式
}FHEADER, *LPHEADER;

struct RIFF_HEADER 
{ 
	char szRiffID[4];  // 'R','I','F','F' 
	DWORD dwRiffSize; 
	char szRiffFormat[4]; // 'W','A','V','E' 
}; 

struct WAVE_FORMAT 
{ 
	WORD wFormatTag; 
	WORD wChannels; 
	DWORD dwSamplesPerSec; 
	DWORD dwAvgBytesPerSec; 
	WORD wBlockAlign; 
	WORD wBitsPerSample; 
}; 
struct waveHead 
{ 
	RIFF_HEADER riff; 
	char  szFmtID[4]; // 'f','m','t',' ' 
	DWORD  dwFmtSize; 
	WAVE_FORMAT wavFormat; 
}; 

struct FACT_BLOCK 
{ 
	char  szFactID[4]; // 'f','a','c','t' 
	DWORD  dwFactSize; 
}; 

struct DATA_BLOCK 
{ 
	char szDataID[4]; // 'd','a','t','a' 
	DWORD dwDataSize; 
}; 
#endif